home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / asm_msc1.arc / EXECSUB.ASM < prev    next >
Assembly Source File  |  1988-11-20  |  3KB  |  121 lines

  1. ; EXECSUB - execute program from compiled BASIC - requires DOS 2.00
  2. ; Copyright 1983 Data Base Decisions
  3. ; CALL EXECSUB(PROG$,PARM$,FCB1$,FCB2$,RETCD%)
  4. ; PROG$ is the program name (e.g. 'command.com')
  5. ; PARM$ is the parameter to be passed to the program (e.g. '/c dir *.bas')
  6. ; FCB1$ is the first file control block (required by some programs)
  7. ; FCB2$ is the second file control block (required by some programs)
  8. ; RETCD% is the error return code
  9.  
  10.     skip equ 2        ; 1 for interpretive, 2 for compiled
  11.  
  12. cseg    segment para public 'code'
  13. public    execsub
  14. execsub proc far
  15.  
  16.     assume cs:cseg,ds:cseg,ss:nothing,es:nothing
  17.  
  18.     push bp
  19.     mov bp,sp
  20.     jmp p010
  21.  
  22. stak    equ this byte
  23.     dw 0            ; save sp
  24.     dw 0            ; save ss
  25.  
  26. prm1    equ this byte
  27.     dw 0            ; environment
  28. prm2    equ this word
  29.     dw 0            ; command line - ip & cs
  30.     dw 0
  31. prm3    equ this byte
  32.     dw 0            ; default FCB - ip & cs
  33.     dw 0
  34. prm4    equ this byte
  35.     dw 0            ; second default FCB - ip & cs
  36.     dw 0
  37.  
  38. p010:
  39.     mov ax,0        ; get psp
  40.     mov es,ax
  41.     mov di,4f2h        ; point to dos comm. area
  42.     mov ax,es:[di]        ; get psp segment
  43.     mov es,ax
  44.     mov di,2
  45.     mov bx,es:[di]        ; get top of memory
  46.     sub bx,ax        ; subtract psp
  47.     mov ah,4ah
  48.     int 21h         ; free memory
  49.     jnc p020        ; no error
  50.     mov ah,0        ; memory error
  51.     jmp p090        ; to error control
  52.  
  53. p020:    mov si,[bp+12]        ; point to parm$
  54.     add si,skip
  55.     mov ax,[si]
  56.     mov si,offset prm2    ; establish command line
  57.     mov cs:[si],ax
  58.     mov ax,ds
  59.     mov cs:[si+2],ax
  60.  
  61.     mov si,[bp+10]        ; point to fcb1$
  62.     add si,skip
  63.     mov ax,[si]
  64.     mov si,offset prm3
  65.     mov cs:[si],ax
  66.     mov ax,ds
  67.     mov cs:[si+2],ax
  68.  
  69.     mov si,[bp+8]        ; point to fcb2$
  70.     add si,skip
  71.     mov ax,[si]
  72.     mov si,offset prm4    ; establish second fcb
  73.     mov cs:[si],ax
  74.     mov ax,ds
  75.     mov cs:[si+2],ax
  76.  
  77.     push bp         ; save registers
  78.     push ds
  79.     push es
  80.     pushf
  81.     mov si,offset stak    ; save stack
  82.     mov cs:[si],sp
  83.     mov cs:[si+2],ss
  84.  
  85.     mov ah,4bh        ; load prog
  86.     mov al,0        ; load & execute
  87.     mov si,[bp+14]        ; point to prog$
  88.     add si,skip
  89.     mov dx,[si]
  90.     push cs
  91.     pop es
  92.     mov bx,offset prm1    ; point to parameter
  93.     int 21h         ; load & execute program
  94.     jnc p050        ; no error
  95.     mov ah,1        ; set error code
  96.     jmp p060
  97.  
  98. p050:    mov ax,0        ; clear error
  99.  
  100. p060:    mov bx,cs        ; restore stack
  101.     mov ds,bx
  102.     mov si,offset stak
  103.     cli            ; no interrupts
  104.     mov sp,cs:[si]
  105.     mov ss,cs:[si+2]
  106.     sti            ; allow interrupts
  107.     popf            ; restore registers
  108.     pop es
  109.     pop ds
  110.     pop bp
  111.  
  112. p090:    mov si,[bp+6]        ; point to RETCD%
  113.     mov [si],ax        ; return error, if any
  114.  
  115.     pop bp            ; return to caller
  116.     ret 10
  117.  
  118. execsub endp
  119. cseg    ends
  120. end
  121.